from selenium import webdriver
from unittest import TestCase
from  ddt import ddt,data,unpack
from LoginData import LoginData
from LoginOperation import LoginOperation
from loginexcel import Exel_options
@ddt
class TestWeb(TestCase):
    @data(*LoginData.login_success_data)
    @unpack
    def testLoginSuccess(self,name,pwd,expect,row):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.41.136:90")

        log = LoginOperation()
        log.login(driver, name, pwd)

        result = log.getSuccessResult(driver)
        driver.quit()

        E=Exel_options('Automation.xlsx')
        E.Write_Exel(0,row,expect,result)
        self.assertEqual(result,expect)

    @data(*LoginData.login_name_error_data)
    @unpack
    def testLoginNameError(self, name, pwd, expect,row):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.41.136:90")

        log = LoginOperation()
        log.login(driver, name, pwd)

        result = log.getNameErrorResult(driver)
        driver.quit()
        E = Exel_options('Automation.xlsx')
        E.Write_Exel(1, row, expect, result)

        self.assertEqual(result, expect)

    @data(*LoginData.login_pwd_error_data)
    @unpack
    def testLoginPwdError(self, name, pwd, expect,row):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.41.136:90")

        log = LoginOperation()
        log.login(driver, name, pwd)

        result = log.getPwdErrorResult(driver)
        driver.quit()
        E = Exel_options('Automation.xlsx')
        E.Write_Exel(2, row, expect, result)

        self.assertEqual(result, expect)
